import { defineStore } from 'pinia'
import { ref } from 'vue'
import { fetchDashboardData, fetchTexts, fetchImages, fetchLogs } from '@/api/data'

interface DashboardStats {
  textCount: number
  imageCount: number
  todayTexts: number
  todayImages: number
}

export const useDataStore = defineStore('data', () => {
  const dashboardStats = ref<DashboardStats>({
    textCount: 0,
    imageCount: 0,
    todayTexts: 0,
    todayImages: 0
  })
  
  const growthData = ref([])
  const distributionData = ref([])
  const recentLogs = ref([])
  
  const texts = ref([])
  const images = ref([])
  const logs = ref([])
  
  async function fetchDashboardData() {
    const data = await fetchDashboardData()
    dashboardStats.value = data.stats
    growthData.value = data.growth
    distributionData.value = data.distribution
    recentLogs.value = data.recentLogs
  }
  
  async function fetchTexts() {
    texts.value = await fetchTexts()
  }
  
  async function fetchImages() {
    images.value = await fetchImages()
  }
  
  async function fetchLogs() {
    logs.value = await fetchLogs()
  }
  
  return {
    dashboardStats,
    growthData,
    distributionData,
    recentLogs,
    texts,
    images,
    logs,
    fetchDashboardData,
    fetchTexts,
    fetchImages,
    fetchLogs
  }
})